package com.app.server.impl;

import com.app.mapper.AdminRoleMapper;
import com.app.model.AdminRoleModel;
import com.app.model.CategoryModel;
import com.app.server.AdminRoleService;
import com.app.utils.StringTool;
import com.app.vo.AdminRoleVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRoleModel> implements AdminRoleService {

    @Autowired
    private AdminRoleMapper adminRoleMapper;

    //分页查询角色列表
    @Override
    public AdminRoleVo getRoleList(Integer page, Integer limit, String roleName) {
        LambdaQueryWrapper<AdminRoleModel> lqw = new LambdaQueryWrapper<>();
        if (StringTool.isNotEmpty(roleName)) {
            lqw.eq(AdminRoleModel::getRoleName, roleName);
        }
        Page<AdminRoleModel> page1 = new Page<>(page, limit);
        Page<AdminRoleModel> adminRolePage = adminRoleMapper.selectPage(page1, lqw);
        List<AdminRoleModel> roleList = adminRolePage.getRecords();
        long count = adminRolePage.getTotal();
        AdminRoleVo adminRoleVo = new AdminRoleVo();
        adminRoleVo.setList(roleList);
        adminRoleVo.setCount((int) count);
        return adminRoleVo;
    }

    @Override
    public List<AdminRoleModel> getRoleByStatus() {
        QueryWrapper<AdminRoleModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        return adminRoleMapper.selectList(queryWrapper);
    }
}
